import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import cookieSession from 'cookie-session';
//后续会增加图片上传

//引入router
import {router} from './routes/apiRouter';

const app=express();

//配置中间件
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(cookieParser("useker.cn"));
app.use(cookieSession({
    name:"useker.cn",
    keys:["aaa","bbb","ccc"],
    expires:1000*60*20
}));
//搭建一个静态资源服务器
//把public文件夹暴露在外面  人人都可以访问public文件夹
app.use(express.static("./public"));

var whiteList=["/api/login","api/reg","api/checkname"]



//拦截器
app.all("*",(req,res,next)=>{
    res.header("Content-Type","application/json;charset=utf-8");
    res.header("Access-Control-Allow-Origin","*");
    next();
})


//配置路由
app.use("/api",router);

app.listen(8080,()=>{
    console.log("服务启动完毕...")
})